package com.ymatou.iapi.userservice.testcase;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.UserRegisterTimeRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.resp.UserRegisterTime;
import com.ymatou.iapi.userservice.parameter.resp.UserRegisterTimeResp;
import com.ymatou.iapi.userservice.service.UserRegisterTimeRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
/**
*根据userId批量查询用户注册时间Test
*FreeMaker Template自动生成代码
*买家app-直播-商家-入驻时间
*/
@TestSuite
public class Ts_UserRegisterTimeRequestDto{
	private static UserRegisterTimeRequestDtoBean userregistertimerequestdtoBean;
	private static UserRegisterTimeRequestDtoCall userregistertimerequestdtoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据userId批量查询用户注册时间Test");
	}

	@Before
	public void caseUp() {
		userregistertimerequestdtoBean=new UserRegisterTimeRequestDtoBean();
		userregistertimerequestdtoCall=new UserRegisterTimeRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(userregistertimerequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UserRegisterTimeRequestDto_001() {
		Logger.start(true,"根据userId批量查询用户注册时间,输入userid集合,成功");
		try {
			List<Integer> UserIds = new ArrayList<>();
			for(int i = 0; i < 3; i++){
				CreateUserReq cur = new CreateUserReq();
				cur = JUserCallService.initCreateUserBean(cur);
				Integer uid = JUserCallService.createUserCall(cur);
				//UserIds.add(uid);
			}
			UserIds.add(20373128);
			userregistertimerequestdtoBean.setUserIds(UserIds);
			userregistertimerequestdtoCall.setData(userregistertimerequestdtoBean);
			userregistertimerequestdtoCall.callService();	
			verifyOk();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UserRegisterTimeRequestDto_002() {
		Logger.start(true,"根据userId批量查询用户注册时间,输入一个userid,成功");
		try {
			List<Integer> UserIds = new ArrayList<>();
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			UserIds.add(uid);
			userregistertimerequestdtoBean.setUserIds(UserIds);
			userregistertimerequestdtoCall.setData(userregistertimerequestdtoBean);
			userregistertimerequestdtoCall.callService();	
			verifyOk();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UserRegisterTimeRequestDto_003() {
		Logger.start(false,"根据userId批量查询用户注册时间,输入不存在的userid,失败");
		try {
			List<Integer> UserIds = new ArrayList<>();
			UserIds.add(999999999);
			userregistertimerequestdtoBean.setUserIds(UserIds);
			userregistertimerequestdtoCall.setData(userregistertimerequestdtoBean);
			userregistertimerequestdtoCall.callService();	
			verifyErr();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UserRegisterTimeRequestDto_004() {
		Logger.start(false,"根据userId批量查询用户注册时间,输入userid为空,失败");
		try {
			List<Integer> UserIds = new ArrayList<>();
			UserIds.add(null);
			userregistertimerequestdtoBean.setUserIds(UserIds);
			userregistertimerequestdtoCall.setData(userregistertimerequestdtoBean);
			userregistertimerequestdtoCall.callService();	
			verifyErr();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/**
	 * 成功断言
	 */
	private void verifyOk()
	{
		JUserWapper ju = new JUserWapper();
		UserRegisterTimeResp resp=userregistertimerequestdtoCall.getResultData();
		List<UserRegisterTime> Result=resp.getResult();
		for(int i=0;i<Result.size();i++)
		{
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			List<Userinfo> lui = ju.selectUserinfoByUid(Result.get(i).getUserId());
			Userinfo ui = lui.get(0);
			Logger.verifyEquals(ui.getUserId(), Result.get(i).getUserId(), "验证第"+i+"个用户信息的userid");
			Logger.verifyEquals(formatter.format(ui.getRegisterTime()), Result.get(i).getRegisterTime(), "验证第"+i+"个用户信息的RegisterTime");
		}
		Logger.verifyEquals(true, resp.getSuccess(), "验证Success");
		Logger.verifyEquals(200, resp.getResponseCode(), "验证ResponseCode");
	}
	private void verifyErr()
	{
		UserRegisterTimeResp resp=userregistertimerequestdtoCall.getResultData();
		Logger.verifyEquals(true, resp.getSuccess(), "验证Success");
		Logger.verifyEquals(100001, resp.getResponseCode(), "验证ResponseCode");
	}
}